/*
 * SiFiSy - A File System Simulator
 * Copyright (C) 2010  SevenSoft
 *
 * This file is part of SiFiSy.
 *
 * SiFiSy is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * SiFiSy is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with SiFiSy.  If not, see <http://www.gnu.org/licenses/>.
 */

package sifisy.newgui;

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.border.TitledBorder;
import java.util.Vector;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import sifisy.core.Model;

/**
 * @author Giuseppe Biolo
 * @version %I%, %G%
 * @createData 31/05/2010
 */
public class HelpWizard extends JFrame {
    private JList entries;
    private Vector<String> helpItems;
    private JTextArea helpText;
    private JButton closeButton;

    private void initComponents() {
        helpItems = new Vector<String>();
        helpItems.add("ntfs");
        helpItems.add("fat");
        helpItems.add("inode");
        helpItems.add("fileSystem");
        helpItems.add("file");
        helpItems.add("ext2");
        helpItems.add("partition");
        helpItems.add("block");
        helpItems.add("hardDisk");
        helpItems.add("fragmentation");
        entries = new JList(helpItems);
        helpText = new JTextArea();
        helpText.setEditable(false);
        helpText.setLineWrap(true);
        closeButton = new JButton(Model.translate("closeButton"));

        closeButton.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                (HelpWizard.this).dispose();
            }
        });
        entries.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                helpText.setText(Model.conceptualHelp((String)entries.getSelectedValue()));
            }
        });
    }

    public HelpWizard() {
        super("SiFiSy - " + Model.translate("conceptualHelp"));
        setLayout(new BorderLayout());
        setSize(500,300);
        initComponents();
        JScrollPane helpTextScroll = new JScrollPane(helpText);
        JPanel entriesPanel = new JPanel(new GridLayout(1,1));
        entries.setBorder(new TitledBorder(Model.translate("entries")));
        entriesPanel.add(new JScrollPane(entries));
        JPanel helpTextPanel = new JPanel(new GridLayout(1,1));
        helpTextPanel.setBorder(new TitledBorder("Help"));
        helpTextPanel.add(helpTextScroll);
        JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        buttonsPanel.add(closeButton);
        add(entriesPanel,BorderLayout.WEST);
        add(helpTextPanel,BorderLayout.CENTER);
        add(buttonsPanel,BorderLayout.SOUTH);
        helpText.setText(Model.translate("selectEntry"));
    }
}
